﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

using PowerCreator.LMS.Common.Script;
using Telerik.WebControls;
using PowerCreator.LMS.Common.Utils;
using PowerCreator.LMS.Common.Upload;

public partial class sysadmin_mavinManager_UploadFile : PowerCreator.LMS.Web.Base.BasePage
{

    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            string mavinID = "0";
            if (Request.QueryString["MavinID"] != null)
            {
                mavinID = Request.QueryString["MavinID"].ToString();
            }
            ViewState["MavinID"] = mavinID;
            InitPage();
        }
    }

    protected override void InitPage()
    {

        lbl_File.Text = GetLanageValueByKey("lbl_Resource_File", PowerCreator.LMS.Language.LanagetItemType.Page);
        btn_UploadFile.Text = GetLanageValueByKey("btn_Resource_File", PowerCreator.LMS.Language.LanagetItemType.Page);
        btn_Back.Text = GetLanageValueByKey("btn_Resource_Back", PowerCreator.LMS.Language.LanagetItemType.Page);

        lbl_Description_title.Text = GetLanageValueByKey("lbl_UploadResource_Description_title", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_Description_1.Text = GetLanageValueByKey("lbl_Resource_Description_1", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_Description_2.Text = GetLanageValueByKey("lbl_Resource_Description_2", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_Description_3.Text = GetLanageValueByKey("lbl_Resource_Description_3", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_Description_4.Text = GetLanageValueByKey("lbl_Resource_Description_4", PowerCreator.LMS.Language.LanagetItemType.Page);

        base.InitPage();
    }
    protected void btnUploadFile_Click(object sender, EventArgs e)
    {
        foreach (UploadedFile file in RadUploadContext.Current.UploadedFiles)
        {
            string Path = Server.MapPath("../../fileManager/MavinPic/");

            //如果路径不存在，则创建
            if (System.IO.Directory.Exists(Path) == false)
            {
                System.IO.Directory.CreateDirectory(Path);
            }

            //组合路径，file.GetName()取得文件名
            string fileName = GetFileName() + file.GetExtension();

            Path = Path + fileName;

            //保存
            file.SaveAs(Path, true);
            //int filesize = file.ContentLength;

            string url = "addmavin.aspx?AddMavin=upload&MavinID=" + ViewState["MavinID"].ToString() + "&fullpath=fileManager/MavinPic/" + fileName;
            Script.RedirectURL(url);
        }
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        string url = "mavinManager.aspx";
        Script.RedirectURL(url);
    }
    /// <summary>
    ///  获取上传资源时文件夹路径
    /// </summary>
    /// <param name="courseID">课程ID</param>
    /// <param name="srt">资源类型</param>
    /// <returns></returns>
    public string GetFileName()
    {
        Random objRand = new Random();
        System.DateTime date = DateTime.Now;
        //生成随机文件名
        string saveName = date.ToString("yyyyMMddHHmmsss") + Convert.ToString(objRand.Next(99) * 97 + 100);

        return saveName;
    }


}
